import sys, asyncio
import os
# os.chdir(os.path.dirname(sys.argv[0]))
if sys.platform == 'win32':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
import multiprocessing
from parameters import para
from CommonMemory import CommonMemory
from DataLoader import DataLoader
from DataProcessor import DataProcessor
import torch

if __name__ == '__main__':
    # pyinstaller 多线程修复
    multiprocessing.freeze_support()
    # 看cuda是否可用
    print("cuda是否可用: ", torch.cuda.is_available())
    
    # 程序逻辑
    globals()[para["ReIDModelGlobalsName"]] = torch.load(para["ReIDModelLoadPath"]).to(torch.device(para["torchDevice"]))
    globals()["_cm"] = CommonMemory()   # 共享内存列表，是一个globals里的变量
    globals()["_cm"].setWaitingFlag()
    dataLoader = DataLoader()

    dataProcessor = DataProcessor(para, globals()["_cm"], globals()[para["ReIDModelGlobalsName"]], dataLoader)
    dataProcessor.start()


# 1. 测量时间，很多次循环 / 循环次数
# 2. scipy.spatial.distance.cdist              float => int
# 3. 思路整理文档，写时间（时效性）